<?php
/**
 * FastApp.
 * 8/17/24
 * @Author 深色的海 (wx:deepsea_0024)
 * @Contact telegram:deepsea159
 */

namespace App\Mall\Api\Controller;

use App\Fastapp\Api\Controller\ApiController;
use App\Mall\Api\Service\OrderService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;

#[Controller('api/mall/order')]
class OrderController extends ApiController
{
    #[Inject]
    public OrderService $service;

    #[GetMapping('list')]
    public function list(): ResponseInterface
    {
        return $this->success($this->service->list());
    }

    #[GetMapping('detail')]
    public function detail(): ResponseInterface
    {
        return $this->success($this->service->detail($this->request->input('id')));
    }

    #[PostMapping('unifiedorder')]
    public function unifiedorder(): ResponseInterface
    {
        return $this->success($this->service->unifiedorder($this->validate([
            'item' => 'required|array',
            'ship_id' => 'integer',
            'time' => 'required',
        ])));
    }

    #[PostMapping('calculatePrice')]
    public function calculatePrice(): ResponseInterface
    {
        return $this->success($this->service->calculatePrice($this->validate([
            'item' => 'required|array'
        ])));
    }
}